package com.hhs.storage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hhs.storage.bean.PersonnelFiles;
import com.hhs.storage.bean.PersonnelFilesType;
import com.hhs.storage.bean.ResponseBean;
import com.hhs.storage.service.PersonnelFilesService;
import com.hhs.storage.service.PersonnelFilesTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chx
 * @since 2024-01-26
 */
@RestController
@RequestMapping("/personnelFiles")
@ApiSupport(order = 1)
@Api(tags = "人事资料")
public class PersonnelFilesController {

    @Resource
    private PersonnelFilesService personnelFilesService;

    @Resource
    private PersonnelFilesTypeService personnelFilesTypeService;

    @PostMapping("uploadFiles")
    @ApiOperation(value = "添加文件类型",
            httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, name = "coding", value = "编码", required =
                    true, paramType = "body"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "fileName", value = "文件名", required =
                    true, paramType = "body"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "fileType", value = "文件类型名称", required =
                    true, paramType = "body"),
            @ApiImplicitParam(dataTypeClass = MultipartFile.class, name = "files", value = "文件(MultipartFile)", required =
                    true, paramType = "body"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "folderName", value = "文件夹名称", required =
                    true, paramType = "body"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "uploadType", value = "上传类型", required =
                    true, paramType = "body"),
    })
    @ApiOperationSupport(order = 1)
    public ResponseBean uploadFiles(@ApiIgnore PersonnelFiles personnelFiles, @ApiIgnore MultipartFile[] files) {
        Map<String, Object> map = personnelFilesService.uploadFiles(personnelFiles, files);
        ResponseBean rb = ResponseBean.getInstance();
        rb.setCode((Integer) map.get("code"));
        rb.setData(map.get("data"));
        return rb;
    }

    @RequestMapping("selectAll")
    @ApiOperation(value = "获取文件类型数据",
            httpMethod = "GET")
    @ApiOperationSupport(order = 1)
    public ResponseBean<PersonnelFilesType> getSelectAll() {
        Map<String, Object> map = personnelFilesTypeService.getSelectAll();
        ResponseBean<PersonnelFilesType> rb = ResponseBean.getInstance();
        rb.setCode((Integer) map.get("code"));
        rb.setData((PersonnelFilesType) map.get("data"));
        return rb;
    }

    @PostMapping("addSelectType")
    @ApiOperation(value = "添加文件类型",
            httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, name = "typeName", value = "文件类型名称", required =
                    true, paramType = "query"),
    })
    @ApiOperationSupport(order = 1)
    public ResponseBean addSelectType(@ApiIgnore PersonnelFilesType personnelFilesType) {
        Map<String, Object> map = personnelFilesTypeService.addSelectType(personnelFilesType);
        ResponseBean rb = ResponseBean.getInstance();
        rb.setCode((Integer) map.get("code"));
        rb.setData(map.get("data"));
        return rb;
    }

}

